package top.jandmla.imagetest.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * <p>
 *  swagger2 配置类
 * </p>
 */
@Configuration
@EnableSwagger2
//@EnableOpenApi
public class SwaggerConfig {

    @Bean
    public Docket jandmla(Environment environment){

        Profiles profile = Profiles.of("dev","test");
        //获取项目环境
        boolean env = environment.acceptsProfiles(profile);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfo(
                        //标题
                        "Jandmla swagger API",
                        //描述
                        "Api，逐梦，随波逐流，随浪而波！",
                        //版本信息
                        "1.0",
                        //团队连接
                        "http://jandmla.top:8080",
                        //作者信息
                        new Contact("逐浪灬", "http://www.jandmla.top:8080", "jandmla@163.com"),
                        //框架版本
                        "Apache 2.0",
                        //框架连接
                        "http://www.apache.org/licenses/LICENSE-2.0",
                        new ArrayList()))
                //是否开启
                .enable(env)
//                .enable(false)
                .groupName("逐浪灬")
                .select()
                //配置扫描地点
//                .apis(RequestHandlerSelectors.basePackage("top.jandmla.springsecurity.controller"))
//                .apis(RequestHandlerSelectors.any())
//                .apis(RequestHandlerSelectors.none())
//                .apis(RequestHandlerSelectors.withMethodAnnotation(RequestMapping.class))
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                //扫描路径
                .paths(PathSelectors.ant("/**"))
                .build();
    }
}
